package com.xuzm.demo.util;

import lombok.Data;

import java.io.Serializable;

@Data
public class Res<T> implements Serializable {

	private final static int ERROR_CODE = 500;

	private int code;

	private String msg;

	private T data;

	public Res() {
		this.msg = "success";
	}

	public Res(T value) {
		this.msg = "success";
		this.data = value;
	}

	public Res<T> error(int code, String msg) {
		this.code = code;
		this.msg = msg;
		return this;
	}

	public Res<T> error(String msg) {
		this.code = ERROR_CODE;
		this.msg = msg;
		return this;
	}

	public Res<T> error(String msg, T data) {
		this.code = ERROR_CODE;
		this.msg = msg;
		this.data = data;
		return this;
	}
}
